package com.prs.crm.dao.hr.impl;

import java.util.ArrayList;
import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.dao.hr.PayrollBillDao;
import com.prs.crm.dao.hr.PayrollDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.hr.Payroll;
import com.prs.crm.domain.hr.Person;

public class PayrollDaoImpl extends BaseDaoImpl<Payroll> implements PayrollDao{
	private PayrollBillDao payrollBillDao;
	
	@Override
	public Collection<Payroll> getAllPayroll() {
		// TODO Auto-generated method stub
		Criteria criteria = this.getSession().createCriteria(Payroll.class);		
		criteria.addOrder(Order.desc("recordTime"));
		return criteria.list();
	}

	@Override
	public Collection<Payroll> getPayrollByIds(Collection<Integer> ids) {
		// TODO Auto-generated method stub
		Criteria criteria = this.getSession().createCriteria(Payroll.class);
		criteria.add(Restrictions.in("id", ids));
		criteria.addOrder(Order.desc("recordTime"));
		return criteria.list();
	}

	@Override
	public Collection<Payroll> getPayrollByPerson(Person person) {
		// TODO Auto-generated method stub
		Collection<Integer> ids = payrollBillDao.getPayrollIdsByPerson(person);
		if(ids.size() != 0) {
			Criteria criteria = this.getSession().createCriteria(Payroll.class);
			criteria.add(Restrictions.in("id", ids));
			criteria.addOrder(Order.desc("recordTime"));
			return criteria.list();
		}
		else {
			return new ArrayList<Payroll>();
		}
	}

	public void setPayrollBillDao(PayrollBillDao payrollBillDao) {
		this.payrollBillDao = payrollBillDao;
	}

	public PayrollBillDao getPayrollBillDao() {
		return payrollBillDao;
	}

}
